<?php

namespace app\admin\controller;

use app\admin\model\EventStatistics;
use app\admin\model\User;
use app\admin\model\GroupChat;
use app\admin\model\GroupChatUser;
use app\common\controller\Backend;
use think\Config;
use think\Hook;
use think\Session;
use think\Validate;

/**
 * 统计
 * @internal
 */
class Event extends Backend
{

    protected $model = null;
    protected $categorylist = [];
    protected $noNeedRight = ['selectpage'];

    public function _initialize()
    {
        parent::_initialize();
        $this->model = new EventStatistics();
    }
    

    public function index()
    {

        //查询最近登录用户
        /* $list = User::field('id')->where(['id'=>['>',34684],'last_login_time'=>['>',time()-(3600*24*7)]])->select();
        foreach ($list as $v) {
            $info = GroupChat::where(['number'=>['<',500]])->order('id asc')->find();
            if($info){
                GroupChatUser::insert(['user_id'=>$v['id'],'group_chat_id'=>$info['id'],'grade'=>1,'add_time'=>time()]);
                GroupChat::where(['id'=>$info['id']])->update(['number'=>$info['number']+1]);
            }
        }
        */




        //设置过滤方法
        $this->request->filter(['strip_tags', 'trim']);
        if ($this->request->isAjax()) {
            //如果发送的来源是Selectpage，则转发到Selectpage
            if ($this->request->request('keyField')) {
                return $this->selectpage();
            }
            list($where, $sort, $order, $offset, $limit) = $this->buildparams();
            $list = $this->model
                ->where($where)
                ->order('id desc')
                ->paginate($limit);
        
            foreach ($list as $k => &$v) {
                $v['user_sum'] = count(explode(',',$v['user_id']));
            }
            $result = array("total" => $list->total(), "rows" => $list->items());
            return json($result);
        }
        return $this->view->fetch();
    }
    



}